import 'package:bruno/bruno.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:interrogation/app/routes/app_pages.dart';

import '../../../../data/models/get_article_res.dart';
import '../controllers/news_list_controller.dart';

class NewsListView extends GetView<NewsListController> {
  const NewsListView({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF1F1F1),
      appBar: BrnAppBar(
        automaticallyImplyLeading: true,
        title: "健康咨询",
        backgroundColor: Colors.white,
        showDefaultBottom: false,
        backLeadCallback: () => Get.back(),
      ),
      body: Obx(() {
        return EasyRefresh(
          controller: controller.refreshController,
          header: const ClassicHeader(),
          footer: const ClassicFooter(),
          onLoad: controller.onLoad,
          onRefresh: controller.onRefresh,
          child: ListView.separated(
            itemCount: controller.list.length,
            itemBuilder: (context, index) {
              return _buildArticleCard(controller.list[index]);
            },
            separatorBuilder: (context, index) {
              return const Divider(
                height: 1,
                color: Color(0xffE5E5E5),
              );
            },
          ),
        );
      }));
  }
  Widget _buildArticleCard(ArticleModel article) {
    return GestureDetector(
      onTap: () {
        Get.toNamed(Routes.NEWS_DETAIL, arguments: article);
      },
      child: Container(
        key: Key('articleCard'),
        padding: EdgeInsets.all(12.w),
        margin: EdgeInsets.symmetric(vertical: 4),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(8.r),
        ),
        child: Row(
          children: [
            SizedBox(width: 12.w),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    article.title??'',
                    style: TextStyle(
                      fontSize: 16.sp,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  SizedBox(height: 4.h),
                  Text(
                    article.content??'',
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 12.sp,
                      color: Colors.grey[600],

                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
